/**
 * Copyright &copy; 2017-2020 <a href="http://www.fosung.com/">FosungFrame</a> All rights reserved.
 */
package com.fosung.frame.modules.score.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.fosung.frame.common.config.Global;
import com.fosung.frame.common.persistence.Page;
import com.fosung.frame.common.web.BaseController;
import com.fosung.frame.common.utils.StringUtils;
import com.fosung.frame.modules.score.entity.OrganizePersonDetail;
import com.fosung.frame.modules.score.service.OrganizePersonDetailService;

/**
 * 党员申请积分明细Controller
 * @author ygl
 * @version 2017-09-03
 */
@Controller
@RequestMapping(value = "${adminPath}/score/organizePersonDetail")
public class OrganizePersonDetailController extends BaseController {

	@Autowired
	private OrganizePersonDetailService organizePersonDetailService;
	
	@ModelAttribute
	public OrganizePersonDetail get(@RequestParam(required=false) String id) {
		OrganizePersonDetail entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = organizePersonDetailService.get(id);
		}
		if (entity == null){
			entity = new OrganizePersonDetail();
		}
		return entity;
	}
	
	@RequiresPermissions("score:organizePersonDetail:view")
	@RequestMapping(value = {"list", ""})
	public String list(OrganizePersonDetail organizePersonDetail, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<OrganizePersonDetail> page = organizePersonDetailService.findPage(new Page<OrganizePersonDetail>(request, response), organizePersonDetail); 
		model.addAttribute("page", page);
		return "modules/score/organizePersonDetailList";
	}

	@RequiresPermissions("score:organizePersonDetail:view")
	@RequestMapping(value = "form")
	public String form(OrganizePersonDetail organizePersonDetail, Model model) {
		model.addAttribute("organizePersonDetail", organizePersonDetail);
		return "modules/score/organizePersonDetailForm";
	}

	@RequiresPermissions("score:organizePersonDetail:edit")
	@RequestMapping(value = "save")
	public String save(OrganizePersonDetail organizePersonDetail, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, organizePersonDetail)){
			return form(organizePersonDetail, model);
		}
		organizePersonDetailService.save(organizePersonDetail);
		addMessage(redirectAttributes, "保存党员申请积分明细成功");
		return "redirect:"+Global.getAdminPath()+"/score/organizePersonDetail/?repage";
	}
	
	@RequiresPermissions("score:organizePersonDetail:edit")
	@RequestMapping(value = "delete")
	public String delete(OrganizePersonDetail organizePersonDetail, RedirectAttributes redirectAttributes) {
		organizePersonDetailService.delete(organizePersonDetail);
		addMessage(redirectAttributes, "删除党员申请积分明细成功");
		return "redirect:"+Global.getAdminPath()+"/score/organizePersonDetail/?repage";
	}

}